﻿using DemoPrism.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoPrism.Services
{
    public class TenantService : ITenantService
    {
        private Tenant _currentTenant;
        private readonly ObservableCollection<Tenant> _availableTenants;

        public Tenant CurrentTenant
        {
            get => _currentTenant;
            private set => SetProperty(ref _currentTenant, value);
        }

        public ObservableCollection<Tenant> AvailableTenants => _availableTenants;

        public event Action<Tenant> TenantChanged;

        public TenantService()
        {
            _availableTenants = new ObservableCollection<Tenant>
        {
            new Tenant { Id = "tenant1", Name = "公司A" },
            new Tenant { Id = "tenant2", Name = "公司B" },
            new Tenant { Id = "tenant3", Name = "公司C" }
        };
        }

        public void SwitchTenant(string tenantId)
        {
            var tenant = _availableTenants.FirstOrDefault(t => t.Id == tenantId);
            if (tenant != null)
            {
                CurrentTenant = tenant;
                TenantChanged?.Invoke(tenant);
            }
        }
    }
}
